package com.zhentao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhentao.dto.RecommendationQueryDTO;
import com.zhentao.pojo.ParamRecommendation;
import com.zhentao.service.ParamRecommendationService;
import com.zhentao.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "AI推荐", description = "参数推荐接口")
@RestController
@RequestMapping("/param/recommendation")
@RequiredArgsConstructor
@Slf4j
public class ParamRecommendationController {

    private final ParamRecommendationService paramRecommendationService;

    @Operation(summary = "分页查询推荐")
    @GetMapping("/page")
    public Result page(RecommendationQueryDTO query) {
        LambdaQueryWrapper<ParamRecommendation> wrapper = new LambdaQueryWrapper<>();
        if (query.getParamId() != null) wrapper.eq(ParamRecommendation::getParamId, query.getParamId());
        if (StringUtils.hasText(query.getRecommendationType())) wrapper.eq(ParamRecommendation::getAlgorithmType, query.getRecommendationType());
        wrapper.orderByDesc(ParamRecommendation::getCreateTime);
        Page<ParamRecommendation> page = new Page<>(query.getPageNum(), query.getPageSize());
        return Result.OK(paramRecommendationService.page(page, wrapper));
    }

    @Operation(summary = "推荐详情")
    @GetMapping("/{id}")
    public Result detail(@PathVariable Long id) {
        return Result.OK(paramRecommendationService.getById(id));
    }
}


